package com.ruoyi.web.controller.app;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import com.ruoyi.app.domain.bo.AppImSystemMessageBo;
import com.ruoyi.app.domain.vo.AppImSystemMessageVo;
import com.ruoyi.app.service.IAppImSystemMessageService;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 系统消息
 *
 * @author ruoyi
 * @date 2025-11-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/imSystemMessage")
public class AppImSystemMessageController extends BaseController {

    private final IAppImSystemMessageService iAppImSystemMessageService;

    /**
     * 查询系统消息列表
     */
    @GetMapping("/list")
    public TableDataInfo<AppImSystemMessageVo> list(AppImSystemMessageBo bo, PageQuery pageQuery) {
        return iAppImSystemMessageService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出系统消息列表
     */
    @Log(title = "系统消息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(AppImSystemMessageBo bo, HttpServletResponse response) {
        List<AppImSystemMessageVo> list = iAppImSystemMessageService.queryList(bo);
        ExcelUtil.exportExcel(list, "系统消息", AppImSystemMessageVo.class, response);
    }

    /**
     * 获取系统消息详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<AppImSystemMessageVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iAppImSystemMessageService.queryById(id));
    }

    /**
     * 新增系统消息
     */
    @Log(title = "系统消息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody AppImSystemMessageBo bo) {
        return toAjax(iAppImSystemMessageService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改系统消息
     */

    @Log(title = "系统消息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody AppImSystemMessageBo bo) {
        return toAjax(iAppImSystemMessageService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除系统消息
     *
     * @param ids 主键串
     */
    @Log(title = "系统消息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iAppImSystemMessageService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
